CREATE procedure [dbo].[amsp_GetSearchableComponents]
@SearchComponentList varchar(1000),
@KeyID numeric
AS
BEGIN
DECLARE
@ComponentCode char(2),
@OldComponentCode char(2),
@ComponentID numeric,
@OldComponentID numeric,
@InterestCategoryID numeric,
@InterestCategoryList varchar(1000),
@l_FirstRow int,
@AdminWebsiteKey uniqueidentifier,
@NavMenuID numeric,
@WebsiteKey uniqueidentifier
CREATE TABLE #temp (
ComponentID varchar(50),
TemplatePath varchar(255),
ComponentCode char(2),
MembersOnlyFlag char(1),
Title varchar(255),
Body1 text,
Body2 text,
InterestCategoryList varchar(3000),
CustomField2 varchar(255),
NavMenuID numeric,
AllWebsiteKeys varchar(1000),
CustomID varchar(50),
IncludeInCrossSiteSearchFlag char(1) Default('Y')
)
SELECT @AdminWebsiteKey = Value
FROM System_Variable
WHERE Name = 'CMAdminWebsiteKey'
IF (CHARINDEX('CM', @SearchComponentList) > 0)
IF @KeyID > 0
INSERT INTO #temp (ComponentID, TemplatePath, ComponentCode, MembersOnlyFlag, Title, Body1, Body2, CustomField2, NavMenuID, AllWebsiteKeys, IncludeInCrossSiteSearchFlag, CustomID)
SELECT cl.ContentID, NULLIF (n.TemplatePath, '') AS Expr1, 'CM' AS Expr2, c.MembersOnlyFlag, cl.LinkName, c.Description, c.Keywords,
CONVERT(VARCHAR(18), ISNULL(M.MicrositeID, '0')) + ',' + CONVERT(varchar(20), ISNULL(c.PublicationDate, CURRENT_TIMESTAMP), 102) AS Expr3,
n.NavMenuID, n.WebsiteKey, w.IncludeInCrossSiteSearchFlag, cl.ContentLinkID
FROM Content_Link AS cl INNER JOIN
vCurrent_Content AS c ON cl.ContentID = c.ContentID INNER JOIN
Nav_Menu AS n ON c.NavMenuID = n.NavMenuID LEFT OUTER JOIN
Microsite AS M ON n.AncestorNavMenuID = M.HomeNavMenuID INNER JOIN
Website AS w ON n.WebsiteKey = w.WebsiteKey
WHERE (n.WebsiteKey <> @AdminWebsiteKey) AND (cl.ContentLinkID = @KeyID) AND (ISNULL(n.HideFlag, 'N') = 'N')
ELSE
INSERT INTO #temp (ComponentID, TemplatePath, ComponentCode, MembersOnlyFlag, Title, Body1, Body2, CustomField2, NavMenuID, AllWebsiteKeys, IncludeInCrossSiteSearchFlag, CustomID)
SELECT cl.ContentID, NULLIF (n.TemplatePath, '') AS Expr1, 'CM' AS Expr2, c.MembersOnlyFlag, cl.LinkName, c.Description, c.Keywords,
CONVERT(VARCHAR(18), ISNULL(M.MicrositeID, '0')) + ',' + CONVERT(varchar(20), ISNULL(c.PublicationDate, CURRENT_TIMESTAMP), 102) AS Expr3,
n.NavMenuID, n.WebsiteKey, w.IncludeInCrossSiteSearchFlag, cl.ContentLinkID
FROM Content_Link AS cl INNER JOIN
vCurrent_Content AS c ON cl.ContentID = c.ContentID INNER JOIN
Nav_Menu AS n ON c.NavMenuID = n.NavMenuID LEFT OUTER JOIN
Microsite AS M ON n.AncestorNavMenuID = M.HomeNavMenuID INNER JOIN
Website AS w ON n.WebsiteKey = w.WebsiteKey
WHERE (n.WebsiteKey <> @AdminWebsiteKey) AND (c.WorkflowStatusCode = 'P') AND (ISNULL(n.HideFlag, 'N') = 'N')
DECLARE c_InterestCategory CURSOR FOR
SELECT cic.ComponentCode,
cic.InterestCategoryID,
cic.ComponentID
FROM Component_Interest_Category cic, #temp t
WHERE cic.ComponentCode = t.ComponentCode
AND cic.ComponentID = t.ComponentID
ORDER BY cic.ComponentCode, cic.ComponentID
OPEN c_InterestCategory
FETCH NEXT FROM c_InterestCategory INTO
@ComponentCode,
@InterestCategoryID,
@ComponentID
SET @OldComponentCode = @ComponentCode
SET @OldComponentID = @ComponentID
SET @InterestCategoryList = @InterestCategoryID
SET @l_FirstRow = 1
WHILE (@@FETCH_STATUS=0) BEGIN
IF ( @OldComponentCode != @ComponentCode or @OldComponentID != @ComponentID ) BEGIN
UPDATE #temp
SET InterestCategoryList = @InterestCategoryList
WHERE ComponentCode = @OldComponentCode
AND ComponentID = @OldComponentID
SET @InterestCategoryList = @InterestCategoryID
END
ELSE BEGIN
IF ( @l_FirstRow = 1 ) BEGIN
SET @InterestCategoryList = @InterestCategoryList + ',' + convert(varchar(10), @InterestCategoryID)
END
ELSE BEGIN
SET @l_FirstRow = 0
END
END
SET @OldComponentCode = @ComponentCode
SET @OldComponentID = @ComponentID
FETCH NEXT FROM c_InterestCategory INTO
@ComponentCode,
@InterestCategoryID,
@ComponentID
END
UPDATE #temp
SET InterestCategoryList = @InterestCategoryList
WHERE ComponentCode = @OldComponentCode
AND ComponentID = @OldComponentID
CLOSE c_InterestCategory
DEALLOCATE c_InterestCategory
UPDATE #temp
SET AllWebsiteKeys = AllWebsiteKeys + ','
WHERE AllWebsiteKeys IS NOT NULL
DECLARE c_NavMenu CURSOR FOR
SELECT DISTINCT b.NavMenuID, b.WebsiteKey
FROM #temp a, Nav_Menu_Website b, Website c
WHERE a.NavMenuID = b.NavMenuID
AND a.AllWebsiteKeys NOT LIKE Convert(varchar(50),b.WebsiteKey) + '%'
AND b.WebsiteKey = Convert(varchar(50),c.WebsiteKey)
AND c.IncludeInCrossSiteSearchFlag = 'Y'
OPEN c_NavMenu
FETCH NEXT FROM c_NavMenu
INTO @NavMenuID,
@WebsiteKey
WHILE @@FETCH_STATUS = 0 BEGIN
UPDATE #temp
SET AllWebsiteKeys = IsNull(AllWebsiteKeys,'') + Convert(varchar(50),@WebsiteKey) + ','
WHERE NavMenuID = @NavMenuID
FETCH NEXT FROM c_NavMenu
INTO @NavMenuID,
@WebsiteKey
END
CLOSE c_NavMenu
DEALLOCATE c_NavMenu
UPDATE #temp
SET AllWebsiteKeys = Left(AllWebsiteKeys,Len(AllWebsiteKeys)-1)
WHERE AllWebsiteKeys IS NOT NULL
UPDATE #temp
SET ComponentID = ComponentID + '-' + CustomID
WHERE CustomID IS NOT NULL
SELECT IsNull(MembersOnlyFlag, 'N') + ':' + ComponentCode + ':' + ComponentID + ':' + IsNull(TemplatePath, 'NONE') as SearchKey,
Title,
Body1,
Body2,
InterestCategoryList,
CASE WHEN AllWebsiteKeys IS NULL THEN ''
ELSE 'WKEY:' + AllWebsiteKeys + ','
END + 'CSEARCH:' + IsNull(IncludeInCrossSiteSearchFlag,'Y') + ',' + CustomField2 AS CustomField2
FROM #temp
END
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
GRANT EXECUTE ON [dbo].[amsp_GetSearchableComponents] TO [IMIS]
GO